using System;
using System.IO;
using System.Reflection; 
using System.Diagnostics;
//using ImageMagickObject;
using System.Runtime.InteropServices;

namespace whole
{
	/// <summary>
	/// Summary description for frameit.
	/// </summary>
	public class frameit
	{
		public const int Thumb = 1;
		public const int Small = 2;

		public frameit()
		{
		}
//		fi.convert2jpg( tmpDst, "80", splashDst );
		public void convert2jpg( string workingPath, string source, string quality, string destination, System.Web.TraceContext Trace)
		{
			Process process = new Process();
			process.StartInfo.FileName = workingPath + "zgif2jpg.pl";
//"C:\\store.01\\travaso.now\\dammela2\\temp\\zgif2jpg.pl";
			//	process.StartInfo.FileName = "convert";
			process.StartInfo.Arguments = source +" "+ quality +" "+ destination;
			process.StartInfo.CreateNoWindow = true;
			//	process.StartInfo.UseShellExecute = false;

			Trace.Write("FileName:"		+process.StartInfo.FileName);
			Trace.Write("Arguments:"	+process.StartInfo.Arguments);

			process.Start();

			if( !process.WaitForExit(30*1000) )
				process.Kill();
		}

		public void frame( string workingPath, string source, int sizes, string randomName, string thumb, string small, System.Web.TraceContext Trace )
		{
			Random rdm = new Random(unchecked((int)DateTime.Now.Ticks));
			
			int frame = rdm.Next(1,5);//frame = 5;
			string frameName = "z" +frame.ToString() +".pl";
			int bg = rdm.Next(1,14);//bg = 5;
			int rotation = 0;

			if( frame == 5 )
				rotation = rdm.Next(355,359) ;
			else
				rotation  = (rdm.Next(0,10) < 4 ) ? (rdm.Next(1,5)) : (rdm.Next(355,359));

			Trace.Write( "Frame will be: " + frame.ToString() );
			Trace.Write( "BG will be: " + bg.ToString() );

			string bgpath = workingPath + "pieces\\" + "bg0"+bg.ToString()+".png";

			if( (sizes & frameit.Thumb) == frameit.Thumb ) 
			{
				Process process = new Process();
				process.StartInfo.FileName = workingPath + frameName;
				process.StartInfo.Arguments = source +" "+ bgpath +" "+ thumb +" "+ rotation +" "+ workingPath ;
				process.StartInfo.CreateNoWindow = true;

				Trace.Write("FileName:"		+process.StartInfo.FileName);
				Trace.Write("Arguments:"	+process.StartInfo.Arguments);

				process.Start();

				if( !process.WaitForExit(30*1000) )
					process.Kill();
			}

			if( (sizes & frameit.Small) == frameit.Small ) 
			{
				Process process = new Process();
				process.StartInfo.FileName = workingPath + "zsmall.pl";
//				process.StartInfo.FileName = "C:\\store.01\\travaso.now\\dammela2\\temp\\zsmall.pl";
				//	process.StartInfo.FileName = "convert";
				process.StartInfo.Arguments = source +" "+ bgpath +" "+ small;
				process.StartInfo.CreateNoWindow = true;
				//	process.StartInfo.UseShellExecute = false;
				process.StartInfo.WorkingDirectory = workingPath;

				process.Start();

				if( !process.WaitForExit(30*1000) )
					process.Kill();
			}
		}
	}
}

/*
		public void frame( string workingPath, string source, int sizes, string randomName, string thumb, string small, System.Web.TraceContext Trace )
		{
			Random rdm = new Random(unchecked((int)DateTime.Now.Ticks));
			
			int frame = rdm.Next(1,5);//frame = 2;
			int bg = rdm.Next(1,14);//bg = 5;

			Trace.Write( "Frame will be: " + frame.ToString() );
			Trace.Write( "BG will be: " + bg.ToString() );

			convert( workingPath + "pieces\\" + "bg0"+bg.ToString()+".png",	workingPath + randomName + ".bg.png" ); 
			Trace.Write("Converted: " + randomName + ".bg.png");

			if( (sizes & frameit.Thumb) == frameit.Thumb ) 
			{
				Trace.Write( "Will be thumb.");

				convert( source, "-trim", "-resize", "90x90", "-bordercolor", "none", "-border", "5", workingPath + randomName + ".1.png" ); 
				Trace.Write( "Converted: " + randomName + ".1.png" );

				switch( frame ) 
				{
					case 1:
						convert( "-bordercolor", "none", "-background", "none", "-compose", "Xor", "-gravity", "center", workingPath + randomName + ".1.png", workingPath + randomName + ".bg.png", "-composite", "-border", "5x5", "-blur", "1x1", "-trim", "-compose", "over", workingPath + "pieces\\" + "pin07.png", "-gravity", "NorthEast", "-composite", workingPath + "pieces\\" + "pin06.png", "-gravity", "SouthWest", "-composite", workingPath + randomName + ".2.png" ); 
						break;
					case 2:
						convert( "-bordercolor", "none", "-background", "none", "-compose", "Xor", "-gravity", "NorthWest", workingPath + randomName + ".1.png", workingPath + randomName + ".bg.png", "-composite", "-border", "5x5", "-blur", "1x1", "-trim", "-compose", "over", workingPath + "pieces\\" + "pin01.png", "-gravity", "East", "-composite", workingPath + "pieces\\" + "pin02.png", "-gravity", "West", "-composite", workingPath + randomName + ".2.png" ); 
						break;
					case 3:
						convert( "-bordercolor", "none", "-background", "none", "-compose", "Xor", "-gravity", "NorthWest", workingPath + randomName + ".1.png", workingPath + randomName + ".bg.png", "-composite", "-border", "5x5", "-blur", "1x1", "-trim", "-compose", "over", workingPath + "pieces\\" + "pin01.png", "-gravity", "NorthEast", "-composite", workingPath + "pieces\\" + "pin02.png", "-gravity", "SouthWest", "-composite", workingPath + "pieces\\" + "pin03.png", "-gravity", "SouthEast", "-composite", workingPath + "pieces\\" + "pin04.png", "-gravity", "NorthWest", "-composite", workingPath + randomName + ".2.png" ); 
						break;
					case 4:
						convert( "-bordercolor", "none", "-background", "none", "-compose", "Xor", "-gravity", "NorthWest", workingPath + randomName + ".1.png", workingPath + randomName + ".bg.png", "-composite", "-border", "10x10", "-blur", "1x1", "-compose", "over", workingPath + "pieces\\" + "tape02.png", "-gravity", "East", "-composite", workingPath + "pieces\\" + "tape01.png", "-gravity", "West", "-composite", workingPath + randomName + ".2.png" ); 
						break;
					case 5:
						convert( "-bordercolor", "none", "-background", "none", "-compose", "Xor", "-gravity", "NorthWest", workingPath + randomName + ".1.png", workingPath + randomName + ".bg.png", "-composite", "-border", "5x8", "-blur", "1x1", "-compose", "over", workingPath + "pieces\\" + "pin09.png", "-gravity", "north", "-composite", workingPath + randomName + ".2.png" ); 
						break;
				}
				Trace.Write("Converted: " + randomName + ".2.png" );

				switch( frame ) 
				{
					case 1:
					case 2:
					case 4:
					case 5:
						convert( workingPath + randomName + ".1.png", "-compose", "over", "-gravity", "center", workingPath + randomName + ".2.png", "-composite", "-shadow", "40x1", workingPath + randomName + ".s.png" ); 
						break;
					case 3:
						break;
				}
				Trace.Write("Converted: " +randomName + ".s.png" );

				switch( frame ) 
				{
					case 1:
						convert( workingPath + randomName + ".s.png", "-bordercolor", "none", "-background", "none", "-border", "20x20", "-implode", ".4", "-chop", "6x6", workingPath + randomName + ".i.png" ); 
						break;
					case 2:
					case 4:
					case 5:
						convert( workingPath + randomName + ".s.png", "-bordercolor", "none", "-background", "none", "-border", "20x20", "-implode", ".6", "-trim", "-splice", "5x5", workingPath + randomName + ".i.png" ); 
						break;
					case 3:
						convert( "-bordercolor", "none", "-background", "none", workingPath + randomName + ".1.png", "-shadow", "40x1", "-shear", "5x0", "-border", "20x20", "-implode", "-1.3", "-trim", workingPath + randomName + ".i.png" ); 
						break;
				}
				Trace.Write("Converted: " + randomName + ".i.png" );

				switch( frame ) 
				{
					case 1:
						convert( workingPath + randomName + ".s.png", "-bordercolor", "none", "-background", "none", "-border", "20x20", "-implode", "-1", "-chop", "6x6", "-trim", workingPath + randomName + ".e.png" ); 
						break;
					case 2:
					case 4:
						convert( workingPath + randomName + ".s.png", "-bordercolor", "none", "-background", "none", "-border", "20x20", "-implode", "-.5", "-splice", "5x5", workingPath + randomName + ".e.png" ); 
						convert( workingPath + randomName + ".e.png", "-resize", "75%x95%", workingPath + randomName + ".e.png" ); 
						break;
					case 5:
						convert( workingPath + randomName + ".s.png", "-bordercolor", "none", "-background", "none", "-border", "20x20", "-implode", "-.5", "-splice", "5x10", workingPath + randomName + ".e.png" ); 
						convert( workingPath + randomName + ".e.png", "-resize", "75%x95%", workingPath + randomName + ".e.png" ); 
						break;
				}
				Trace.Write("Converted: " + randomName + ".e.png" );

				switch( frame ) 
				{
					case 1:
						composite( "-gravity", "center", workingPath + randomName + ".e.png", workingPath + randomName + ".i.png", "-compose", "over", workingPath + randomName + ".o.png" ); 
						convert( "-bordercolor", "none", "-background", "none", workingPath + randomName + ".o.png", "-shear", "0x1", "-shear", "-2x0", "-implode", ".6", "-splice", "4x4", "-shear", "-2x0", workingPath + randomName + ".o.png" ); 
						break;
					case 2:
						composite( "-gravity", "center", workingPath + randomName + ".e.png", workingPath + randomName + ".i.png", "-compose", "over", workingPath + randomName + ".o.png" ); 
						convert( "-bordercolor", "none", "-background", "none", workingPath + randomName + ".o.png", "-implode", "-1", "-resize", "105%", "-trim", "-rotate", "-1", workingPath + randomName + ".o.png" ); 
						break;
					case 4:
						composite( "-gravity", "center", workingPath + randomName + ".e.png", workingPath + randomName + ".i.png", "-compose", "over", workingPath + randomName + ".o.png" ); 
						convert( "-bordercolor", "none", "-background", "none", workingPath + randomName + ".o.png", "-implode", "-1", "-resize", "105%", "-rotate", "2", "-trim", workingPath + randomName + ".o.png" ); 
						break;
					case 5:
						composite( "-gravity", "center", workingPath + randomName + ".e.png", workingPath + randomName + ".i.png", "-compose", "over", workingPath + randomName + ".o.png" ); 
						convert( "-bordercolor", "none", "-background", "none", workingPath + randomName + ".o.png", "-implode", "-1", "-resize", "105%", "-rotate", "-1", "-trim", workingPath + randomName + ".o.png" ); 
						break;
				}
				Trace.Write("Converted: " + randomName + ".o.png" );

				switch( frame ) 
				{
					case 1:
					case 2:
					case 4:
					case 5:
						composite( "-gravity", "center", workingPath + randomName + ".1.png", workingPath + randomName + ".o.png", "-compose", "over", workingPath + randomName + ".f.png" ); 
						break;
					case 3:
						composite( "-gravity", "center", workingPath + randomName + ".1.png", workingPath + randomName + ".i.png", "-compose", "over", workingPath + randomName + ".f.png" ); 
						break;
				}
				Trace.Write("Composite: " + randomName + ".f.png" );

				composite( "-gravity", "center", workingPath + randomName + ".2.png", workingPath + randomName + ".f.png", "-compose", "over", workingPath + randomName + ".f.png" ); 
				Trace.Write("Composite: " + randomName + ".f.png" );

				convert( workingPath + randomName + ".f.png", "-background", "white", "-rotate", (rdm.Next(0,10) < 4 ) ? (rdm.Next(1,5).ToString()) : (rdm.Next(355,359).ToString()), "-trim", "+repage", "-quality", "80", thumb ); 
				Trace.Write("Converted: " + thumb );
			}

			if( (sizes & frameit.Small) == frameit.Small ) 
			{
				Trace.Write( "Will be small.");

				convert( source, "-trim", "-resize", "230x170", "-bordercolor", "none", "-border", "5", workingPath + randomName + ".1.png" ); 
				Trace.Write( "Converted: " + randomName + ".1.png" );

				convert( "-bordercolor", "none", "-background", "none", "-compose", "Xor", "-gravity", "center", workingPath + randomName + ".1.png", workingPath + randomName + ".bg.png", "-composite", "-border", "5x5", "-blur", "1x1", "-trim", workingPath + randomName + ".2.png" ); 
				Trace.Write("Converted: " + randomName + ".2.png" );

				convert( workingPath + randomName + ".1.png", "-compose", "over", "-gravity", "center", workingPath + randomName + ".2.png", "-composite", "-shadow", "40x1", workingPath + randomName + ".s.png" ); 
				Trace.Write("Converted: " +randomName + ".s.png" );

//				convert( "-background", "white", workingPath + randomName + ".1.png", "-compose", "over", "-gravity", "center", workingPath + randomName + ".s.png", "-composite", workingPath + randomName + ".f.png" ); 
//				Trace.Write("Composite: " + randomName + ".f.png" );

				composite( "-gravity", "center", workingPath + randomName + ".2.png", workingPath + randomName + ".1.png", "-compose", "over", workingPath + randomName + ".f.png" ); 
				Trace.Write("Composite: " + randomName + ".f.png" );

				convert( workingPath + randomName + ".f.png", "-background", "white", "-trim", "+repage", "-quality", "80", small ); 
				Trace.Write("Converted: " + small );
			}

			File.Delete( workingPath + randomName + ".1.png" );
			File.Delete( workingPath + randomName + ".2.png" );
			File.Delete( workingPath + randomName + ".bg.png" );
			File.Delete( workingPath + randomName + ".s.png" );
			File.Delete( workingPath + randomName + ".i.png" );
			File.Delete( workingPath + randomName + ".e.png" );
			File.Delete( workingPath + randomName + ".o.png" );
			File.Delete( workingPath + randomName + ".f.png" );

			Trace.Write("Deleted: pieces!");

		}
	}
*/

//	public class frameit : System.IDisposable
//	{
//		private Type comType; 
//		private object comObject; 
//		private bool disposed = false;
//
//		public const int Thumb = 1;
//		public const int Small = 2;
//
//		public frameit()
//		{
//			comType=Type.GetTypeFromProgID("ImageMagickObject.MagickImage.1"); 
//			comObject=Activator.CreateInstance(comType); 
//		}
//		~frameit() 
//		{
//			Dispose(false);
//		}
//		public void Dispose() 
//		{
//			Dispose(true);
//			GC.SuppressFinalize(this);
//		}
//		private void Dispose( bool disposing ) 
//		{
//			if( !this.disposed ) 
//			{
//				if( disposing )
//				{
//				}
//
//				int referenceCount = 0;
//				do
//				{
//					referenceCount = System.Runtime.InteropServices.Marshal.ReleaseComObject(this.comObject);
//				}
//				while (referenceCount > 0); 
//			}
//			disposed = true;
//		}
//		public void convert(params object[] Parameters)
//		{
///*
//			using ( ImageMagickObject.MagickImage img = new ImageMagickObject.MagickImageClass() )
//			{
//				img.Convert( ref Parameters ); 
//			}
//*/
//			comType.InvokeMember("convert", BindingFlags.InvokeMethod, null, comObject, Parameters ); 
//		}
//
//		public void frame( string workingPath, string source, int sizes, string randomName, string thumb, string small, System.Web.TraceContext Trace )
//		{
//			Random rdm = new Random(unchecked((int)DateTime.Now.Ticks));
//			
//			int frame = rdm.Next(1,5);frame = 5;
//			int bg = rdm.Next(1,14);//bg = 5;
//			int rotation = 0;
//
//			if( frame == 5 )
//				rotation = rdm.Next(355,359) ;
//			else
//				rotation  = (rdm.Next(0,10) < 4 ) ? (rdm.Next(1,5)) : (rdm.Next(355,359));
//
//			Trace.Write( "Frame will be: " + frame.ToString() );
//			Trace.Write( "BG will be: " + bg.ToString() );
//
//			string bgpath = workingPath + "pieces\\" + "bg0"+bg.ToString()+".png";
//
//			Process process = new Process();
//			process.StartInfo.FileName = "C:\\store.01\\travaso.now\\dammela2\\temp\\z5.pl";
//			//	process.StartInfo.FileName = "convert";
//			process.StartInfo.Arguments = source +" "+ bg +" "+ thumb +" "+ rotation;
//			process.StartInfo.CreateNoWindow = true;
//			//	process.StartInfo.UseShellExecute = false;
//			process.StartInfo.WorkingDirectory = workingPath;
//
//			process.Start();
//
//			if( !process.WaitForExit(80) )
//				process.Kill();
//
//			process = new Process();
//			process.StartInfo.FileName = "C:\\store.01\\travaso.now\\dammela2\\temp\\zsmall.pl";
//			//	process.StartInfo.FileName = "convert";
//			process.StartInfo.Arguments = source +" "+ bg +" "+ small;
//			process.StartInfo.CreateNoWindow = true;
//			//	process.StartInfo.UseShellExecute = false;
//			process.StartInfo.WorkingDirectory = workingPath;
//
//			process.Start();
//
//			if( !process.WaitForExit(80) )
//				process.Kill();
//
///*			
//			ImageMagickObject.MagickImage img = new ImageMagickObject.MagickImageClass();
////			convert( workingPath + "pieces\\" + "bg0"+bg.ToString()+".png",	workingPath + randomName + ".bg.png" ); 
//			File.Copy( workingPath + "pieces\\" + "bg0"+bg.ToString()+".png",	workingPath + randomName + ".bg.png" ); 
//			Trace.Write("Moved: " + randomName + ".bg.png");
//
//			if( (sizes & frameit.Thumb) == frameit.Thumb ) 
//			{
//				Trace.Write( "Will be thumb.");
//
//				convert( source, "-trim", "-resize", "90x90", "-bordercolor", "none", "-border", "5", workingPath + randomName + ".1.png" ); 
//				Trace.Write( "Converted: " + randomName + ".1.png" );
//
//				switch( frame ) 
//				{
//					case 1:
//						convert( "-bordercolor", "none", "-background", "none", "-compose", "Xor", "-gravity", "center", workingPath + randomName + ".1.png", workingPath + randomName + ".bg.png", "-composite", "-border", "5x5", "-blur", "1x1", "-trim", "-compose", "over", workingPath + "pieces\\" + "pin07.png", "-gravity", "NorthEast", "-composite", workingPath + "pieces\\" + "pin06.png", "-gravity", "SouthWest", "-composite", workingPath + randomName + ".2.png" ); 
//						break;
//					case 2:
//						convert( "-bordercolor", "none", "-background", "none", "-compose", "Xor", "-gravity", "NorthWest", workingPath + randomName + ".1.png", workingPath + randomName + ".bg.png", "-composite", "-border", "5x5", "-blur", "1x1", "-trim", "-compose", "over", workingPath + "pieces\\" + "pin01.png", "-gravity", "East", "-composite", workingPath + "pieces\\" + "pin02.png", "-gravity", "West", "-composite", workingPath + randomName + ".2.png" ); 
//						break;
//					case 3:
//						convert( "-bordercolor", "none", "-background", "none", "-compose", "Xor", "-gravity", "NorthWest", workingPath + randomName + ".1.png", workingPath + randomName + ".bg.png", "-composite", "-border", "5x5", "-blur", "1x1", "-trim", "-compose", "over", workingPath + "pieces\\" + "pin01.png", "-gravity", "NorthEast", "-composite", workingPath + "pieces\\" + "pin02.png", "-gravity", "SouthWest", "-composite", workingPath + "pieces\\" + "pin03.png", "-gravity", "SouthEast", "-composite", workingPath + "pieces\\" + "pin04.png", "-gravity", "NorthWest", "-composite", workingPath + randomName + ".2.png" ); 
//						break;
//					case 4:
//						convert( "-bordercolor", "none", "-background", "none", "-compose", "Xor", "-gravity", "NorthWest", workingPath + randomName + ".1.png", workingPath + randomName + ".bg.png", "-composite", "-border", "10x10", "-blur", "1x1", "-compose", "over", workingPath + "pieces\\" + "tape02.png", "-gravity", "East", "-composite", workingPath + "pieces\\" + "tape01.png", "-gravity", "West", "-composite", workingPath + randomName + ".2.png" ); 
//						break;
//					case 5:
//						convert( "-bordercolor", "none", "-background", "none", "-compose", "Xor", "-gravity", "NorthWest", workingPath + randomName + ".1.png", workingPath + randomName + ".bg.png", "-composite", "-border", "5x8", "-blur", "1x1", "-compose", "over", workingPath + "pieces\\" + "pin09.png", "-gravity", "north", "-composite", workingPath + randomName + ".2.png" ); 
//						break;
//				}
//				Trace.Write("Converted: " + randomName + ".2.png" );
//
//				switch( frame ) 
//				{
//					case 1:
//					case 2:
//					case 4:
//					case 5:
//						convert( workingPath + randomName + ".1.png", "-compose", "over", "-gravity", "center", workingPath + randomName + ".2.png", "-composite", "-shadow", "40x1", workingPath + randomName + ".s.png" ); 
//						break;
//					case 3:
//						break;
//				}
//				Trace.Write("Converted: " +randomName + ".s.png" );
//
//				switch( frame ) 
//				{
//					case 1:
//						convert( workingPath + randomName + ".s.png", "-bordercolor", "none", "-background", "none", "-border", "20x20", "-implode", ".4", "-chop", "6x6", workingPath + randomName + ".i.png" ); 
//						break;
//					case 2:
//					case 4:
//					case 5:
//						convert( workingPath + randomName + ".s.png", "-bordercolor", "none", "-background", "none", "-border", "20x20", "-implode", ".6", "-trim", "-splice", "5x5", workingPath + randomName + ".i.png" ); 
//						break;
//					case 3:
//						convert( "-bordercolor", "none", "-background", "none", workingPath + randomName + ".1.png", "-shadow", "40x1", "-shear", "5x0", "-border", "20x20", "-implode", "-1.3", "-trim", workingPath + randomName + ".i.png" ); 
//						break;
//				}
//				Trace.Write("Converted: " + randomName + ".i.png" );
//
//				switch( frame ) 
//				{
//					case 1:
//						convert( workingPath + randomName + ".s.png", "-bordercolor", "none", "-background", "none", "-border", "20x20", "-implode", "-1", "-chop", "6x6", "-trim", workingPath + randomName + ".e.png" ); 
//						break;
//					case 2:
//					case 4:
//						convert( workingPath + randomName + ".s.png", "-bordercolor", "none", "-background", "none", "-border", "20x20", "-implode", "-.5", "-splice", "5x5", workingPath + randomName + ".e.png" ); 
//						convert( workingPath + randomName + ".e.png", "-resize", "75%x95%", workingPath + randomName + ".e.png" ); 
//						break;
//					case 5:
//						convert( workingPath + randomName + ".s.png", "-bordercolor", "none", "-background", "none", "-border", "20x20", "-implode", "-.5", "-splice", "5x10", workingPath + randomName + ".e.png" ); 
//						convert( workingPath + randomName + ".e.png", "-resize", "75%x95%", workingPath + randomName + ".e.png" ); 
//						break;
//				}
//				Trace.Write("Converted: " + randomName + ".e.png" );
//
//				switch( frame ) 
//				{
//					case 1:
//						convert( workingPath + randomName + ".i.png", workingPath + randomName + ".e.png", "-compose", "over", "-gravity", "center", "-composite", workingPath + randomName + ".o.png" ); 
//						convert( "-bordercolor", "none", "-background", "none", workingPath + randomName + ".o.png", "-shear", "0x1", "-shear", "-2x0", "-implode", ".6", "-splice", "4x4", "-shear", "-2x0", workingPath + randomName + ".o.png" ); 
//						break;
//					case 2:
//						convert( workingPath + randomName + ".i.png", workingPath + randomName + ".e.png", "-compose", "over", "-gravity", "center", "-composite", workingPath + randomName + ".o.png" ); 
//						convert( "-bordercolor", "none", "-background", "none", workingPath + randomName + ".o.png", "-implode", "-1", "-resize", "105%", "-trim", "-rotate", "-1", workingPath + randomName + ".o.png" ); 
//						break;
//					case 4:
//						convert( workingPath + randomName + ".i.png", workingPath + randomName + ".e.png", "-compose", "over", "-gravity", "center", "-composite", workingPath + randomName + ".o.png" ); 
//						convert( "-bordercolor", "none", "-background", "none", workingPath + randomName + ".o.png", "-implode", "-1", "-resize", "105%", "-rotate", "2", "-trim", workingPath + randomName + ".o.png" ); 
//						break;
//					case 5:
//						convert( workingPath + randomName + ".i.png", workingPath + randomName + ".e.png", "-compose", "over", "-gravity", "center", "-composite", workingPath + randomName + ".o.png" ); 
//						convert( "-bordercolor", "none", "-background", "none", workingPath + randomName + ".o.png", "-implode", "-1", "-resize", "105%", "-rotate", "-1", "-trim", workingPath + randomName + ".o.png" ); 
//						break;
//				}
//				Trace.Write("Converted: " + randomName + ".o.png" );
//
//				switch( frame ) 
//				{
//					case 1:
//					case 2:
//					case 4:
//					case 5:
//						convert( workingPath + randomName + ".o.png", workingPath + randomName + ".1.png", "-compose", "over", "-gravity", "center", "-composite", workingPath + randomName + ".f.png" ); 
//						break;
//					case 3:
//						convert( workingPath + randomName + ".i.png", workingPath + randomName + ".1.png", "-compose", "over", "-gravity", "center", "-composite", workingPath + randomName + ".f.png" ); 
//						break;
//				}
//				Trace.Write("Composite: " + randomName + ".f.png" );
//
//				convert( workingPath + randomName + ".f.png", workingPath + randomName + ".2.png", "-compose", "over", "-gravity", "center", "-composite", workingPath + randomName + ".f.png" ); 
//				Trace.Write("Composite: " + randomName + ".f.png" );
//
//				convert( workingPath + randomName + ".f.png", "-background", "white", "-rotate", (rdm.Next(0,10) < 4 ) ? (rdm.Next(1,5).ToString()) : (rdm.Next(355,359).ToString()), "-trim", "+repage", "-quality", "80", thumb ); 
//				Trace.Write("Converted: " + thumb );
//			}
//*/
///*
//			if( (sizes & frameit.Small) == frameit.Small ) 
//			{
//				Trace.Write( "Will be small.");
//
//				convert( source, "-trim", "-resize", "230x170", "-bordercolor", "none", "-border", "5", workingPath + randomName + ".1.png" ); 
//				Trace.Write( "Converted: " + randomName + ".1.png" );
//
//				convert( "-bordercolor", "none", "-background", "none", "-compose", "Xor", "-gravity", "center", workingPath + randomName + ".1.png", workingPath + randomName + ".bg.png", "-composite", "-border", "5x5", "-blur", "1x1", "-trim", workingPath + randomName + ".2.png" ); 
//				Trace.Write("Converted: " + randomName + ".2.png" );
//
//				convert( workingPath + randomName + ".1.png", "-compose", "over", "-gravity", "center", workingPath + randomName + ".2.png", "-composite", "-shadow", "40x1", workingPath + randomName + ".s.png" ); 
//				Trace.Write("Converted: " +randomName + ".s.png" );
//
//				//				convert( "-background", "white", workingPath + randomName + ".1.png", "-compose", "over", "-gravity", "center", workingPath + randomName + ".s.png", "-composite", workingPath + randomName + ".f.png" ); 
//				//				Trace.Write("Composite: " + randomName + ".f.png" );
//
////				composite( "-gravity", "center", workingPath + randomName + ".2.png", workingPath + randomName + ".1.png", "-compose", "over", workingPath + randomName + ".f.png" ); 
//				convert( workingPath + randomName + ".1.png", workingPath + randomName + ".2.png", "-compose", "over", "-gravity", "center", "-composite", workingPath + randomName + ".f.png" ); 
//				Trace.Write("Composite: " + randomName + ".f.png" );
//
//				convert( workingPath + randomName + ".f.png", "-background", "white", "-trim", "+repage", "-quality", "80", small ); 
//				Trace.Write("Converted: " + small );
//			}
//*/
///*
//			File.Delete( workingPath + randomName + ".1.png" );
//			File.Delete( workingPath + randomName + ".2.png" );
//			File.Delete( workingPath + randomName + ".bg.png" );
//			File.Delete( workingPath + randomName + ".s.png" );
//			File.Delete( workingPath + randomName + ".i.png" );
//			File.Delete( workingPath + randomName + ".e.png" );
//			File.Delete( workingPath + randomName + ".o.png" );
//			File.Delete( workingPath + randomName + ".f.png" );
//*/
////			Trace.Write("Deleted: pieces!");
//
//		}
//	}
//
///*
//		public void frame( string workingPath, string source, int sizes, string randomName, string thumb, string small, System.Web.TraceContext Trace )
//		{
//			Random rdm = new Random(unchecked((int)DateTime.Now.Ticks));
//			
//			int frame = rdm.Next(1,5);//frame = 2;
//			int bg = rdm.Next(1,14);//bg = 5;
//
//			Trace.Write( "Frame will be: " + frame.ToString() );
//			Trace.Write( "BG will be: " + bg.ToString() );
//
//			convert( workingPath + "pieces\\" + "bg0"+bg.ToString()+".png" + " " + 	workingPath + randomName + ".bg.png" ); 
//			Trace.Write("Converted: " + randomName + ".bg.png");
//
//			if( (sizes & frameit.Thumb) == frameit.Thumb ) 
//			{
//				Trace.Write( "Will be thumb.");
//
//				convert( source + " " +  "-trim" + " " +  "-resize" + " " +  "90x90" + " " +  "-bordercolor" + " " +  "none" + " " +  "-border" + " " +  "5" + " " +  workingPath + randomName + ".1.png" ); 
//				Trace.Write( "Converted: " + randomName + ".1.png" );
//
//				switch( frame ) 
//				{
//					case 1:
//						convert( "-bordercolor" + " " +  "none" + " " +  "-background" + " " +  "none" + " " +  "-compose" + " " +  "Xor" + " " +  "-gravity" + " " +  "center" + " " +  workingPath + randomName + ".1.png" + " " +  workingPath + randomName + ".bg.png" + " " +  "-composite" + " " +  "-border" + " " +  "5x5" + " " +  "-blur" + " " +  "1x1" + " " +  "-trim" + " " +  "-compose" + " " +  "over" + " " +  workingPath + "pieces\\" + "pin07.png" + " " +  "-gravity" + " " +  "NorthEast" + " " +  "-composite" + " " +  workingPath + "pieces\\" + "pin06.png" + " " +  "-gravity" + " " +  "SouthWest" + " " +  "-composite" + " " +  workingPath + randomName + ".2.png" ); 
//						break;
//					case 2:
//						convert( "-bordercolor" + " " +  "none" + " " +  "-background" + " " +  "none" + " " +  "-compose" + " " +  "Xor" + " " +  "-gravity" + " " +  "NorthWest" + " " +  workingPath + randomName + ".1.png" + " " +  workingPath + randomName + ".bg.png" + " " +  "-composite" + " " +  "-border" + " " +  "5x5" + " " +  "-blur" + " " +  "1x1" + " " +  "-trim" + " " +  "-compose" + " " +  "over" + " " +  workingPath + "pieces\\" + "pin01.png" + " " +  "-gravity" + " " +  "East" + " " +  "-composite" + " " +  workingPath + "pieces\\" + "pin02.png" + " " +  "-gravity" + " " +  "West" + " " +  "-composite" + " " +  workingPath + randomName + ".2.png" ); 
//						break;
//					case 3:
//						convert( "-bordercolor" + " " +  "none" + " " +  "-background" + " " +  "none" + " " +  "-compose" + " " +  "Xor" + " " +  "-gravity" + " " +  "NorthWest" + " " +  workingPath + randomName + ".1.png" + " " +  workingPath + randomName + ".bg.png" + " " +  "-composite" + " " +  "-border" + " " +  "5x5" + " " +  "-blur" + " " +  "1x1" + " " +  "-trim" + " " +  "-compose" + " " +  "over" + " " +  workingPath + "pieces\\" + "pin01.png" + " " +  "-gravity" + " " +  "NorthEast" + " " +  "-composite" + " " +  workingPath + "pieces\\" + "pin02.png" + " " +  "-gravity" + " " +  "SouthWest" + " " +  "-composite" + " " +  workingPath + "pieces\\" + "pin03.png" + " " +  "-gravity" + " " +  "SouthEast" + " " +  "-composite" + " " +  workingPath + "pieces\\" + "pin04.png" + " " +  "-gravity" + " " +  "NorthWest" + " " +  "-composite" + " " +  workingPath + randomName + ".2.png" ); 
//						break;
//					case 4:
//						convert( "-bordercolor" + " " +  "none" + " " +  "-background" + " " +  "none" + " " +  "-compose" + " " +  "Xor" + " " +  "-gravity" + " " +  "NorthWest" + " " +  workingPath + randomName + ".1.png" + " " +  workingPath + randomName + ".bg.png" + " " +  "-composite" + " " +  "-border" + " " +  "10x10" + " " +  "-blur" + " " +  "1x1" + " " +  "-compose" + " " +  "over" + " " +  workingPath + "pieces\\" + "tape02.png" + " " +  "-gravity" + " " +  "East" + " " +  "-composite" + " " +  workingPath + "pieces\\" + "tape01.png" + " " +  "-gravity" + " " +  "West" + " " +  "-composite" + " " +  workingPath + randomName + ".2.png" ); 
//						break;
//					case 5:
//						convert( "-bordercolor" + " " +  "none" + " " +  "-background" + " " +  "none" + " " +  "-compose" + " " +  "Xor" + " " +  "-gravity" + " " +  "NorthWest" + " " +  workingPath + randomName + ".1.png" + " " +  workingPath + randomName + ".bg.png" + " " +  "-composite" + " " +  "-border" + " " +  "5x8" + " " +  "-blur" + " " +  "1x1" + " " +  "-compose" + " " +  "over" + " " +  workingPath + "pieces\\" + "pin09.png" + " " +  "-gravity" + " " +  "north" + " " +  "-composite" + " " +  workingPath + randomName + ".2.png" ); 
//						break;
//				}
//				Trace.Write("Converted: " + randomName + ".2.png" );
//
//				switch( frame ) 
//				{
//					case 1:
//					case 2:
//					case 4:
//					case 5:
//						convert( workingPath + randomName + ".1.png" + " " +  "-compose" + " " +  "over" + " " +  "-gravity" + " " +  "center" + " " +  workingPath + randomName + ".2.png" + " " +  "-composite" + " " +  "-shadow" + " " +  "40x1" + " " +  workingPath + randomName + ".s.png" ); 
//						break;
//					case 3:
//						break;
//				}
//				Trace.Write("Converted: " +randomName + ".s.png" );
//
//				switch( frame ) 
//				{
//					case 1:
//						convert( workingPath + randomName + ".s.png" + " " +  "-bordercolor" + " " +  "none" + " " +  "-background" + " " +  "none" + " " +  "-border" + " " +  "20x20" + " " +  "-implode" + " " +  ".4" + " " +  "-chop" + " " +  "6x6" + " " +  workingPath + randomName + ".i.png" ); 
//						break;
//					case 2:
//					case 4:
//					case 5:
//						convert( workingPath + randomName + ".s.png" + " " +  "-bordercolor" + " " +  "none" + " " +  "-background" + " " +  "none" + " " +  "-border" + " " +  "20x20" + " " +  "-implode" + " " +  ".6" + " " +  "-trim" + " " +  "-splice" + " " +  "5x5" + " " +  workingPath + randomName + ".i.png" ); 
//						break;
//					case 3:
//						convert( "-bordercolor" + " " +  "none" + " " +  "-background" + " " +  "none" + " " +  workingPath + randomName + ".1.png" + " " +  "-shadow" + " " +  "40x1" + " " +  "-shear" + " " +  "5x0" + " " +  "-border" + " " +  "20x20" + " " +  "-implode" + " " +  "-1.3" + " " +  "-trim" + " " +  workingPath + randomName + ".i.png" ); 
//						break;
//				}
//				Trace.Write("Converted: " + randomName + ".i.png" );
//
//				switch( frame ) 
//				{
//					case 1:
//						convert( workingPath + randomName + ".s.png" + " " +  "-bordercolor" + " " +  "none" + " " +  "-background" + " " +  "none" + " " +  "-border" + " " +  "20x20" + " " +  "-implode" + " " +  "-1" + " " +  "-chop" + " " +  "6x6" + " " +  "-trim" + " " +  workingPath + randomName + ".e.png" ); 
//						break;
//					case 2:
//					case 4:
//						convert( workingPath + randomName + ".s.png" + " " +  "-bordercolor" + " " +  "none" + " " +  "-background" + " " +  "none" + " " +  "-border" + " " +  "20x20" + " " +  "-implode" + " " +  "-.5" + " " +  "-splice" + " " +  "5x5" + " " +  workingPath + randomName + ".e.png" ); 
//						convert( workingPath + randomName + ".e.png" + " " +  "-resize" + " " +  "75%x95%" + " " +  workingPath + randomName + ".e.png" ); 
//						break;
//					case 5:
//						convert( workingPath + randomName + ".s.png" + " " +  "-bordercolor" + " " +  "none" + " " +  "-background" + " " +  "none" + " " +  "-border" + " " +  "20x20" + " " +  "-implode" + " " +  "-.5" + " " +  "-splice" + " " +  "5x10" + " " +  workingPath + randomName + ".e.png" ); 
//						convert( workingPath + randomName + ".e.png" + " " +  "-resize" + " " +  "75%x95%" + " " +  workingPath + randomName + ".e.png" ); 
//						break;
//				}
//				Trace.Write("Converted: " + randomName + ".e.png" );
//
//				switch( frame ) 
//				{
//					case 1:
//						composite( "-gravity" + " " +  "center" + " " +  workingPath + randomName + ".e.png" + " " +  workingPath + randomName + ".i.png" + " " +  "-compose" + " " +  "over" + " " +  workingPath + randomName + ".o.png" ); 
//						convert( "-bordercolor" + " " +  "none" + " " +  "-background" + " " +  "none" + " " +  workingPath + randomName + ".o.png" + " " +  "-shear" + " " +  "0x1" + " " +  "-shear" + " " +  "-2x0" + " " +  "-implode" + " " +  ".6" + " " +  "-splice" + " " +  "4x4" + " " +  "-shear" + " " +  "-2x0" + " " +  workingPath + randomName + ".o.png" ); 
//						break;
//					case 2:
//						composite( "-gravity" + " " +  "center" + " " +  workingPath + randomName + ".e.png" + " " +  workingPath + randomName + ".i.png" + " " +  "-compose" + " " +  "over" + " " +  workingPath + randomName + ".o.png" ); 
//						convert( "-bordercolor" + " " +  "none" + " " +  "-background" + " " +  "none" + " " +  workingPath + randomName + ".o.png" + " " +  "-implode" + " " +  "-1" + " " +  "-resize" + " " +  "105%" + " " +  "-trim" + " " +  "-rotate" + " " +  "-1" + " " +  workingPath + randomName + ".o.png" ); 
//						break;
//					case 4:
//						composite( "-gravity" + " " +  "center" + " " +  workingPath + randomName + ".e.png" + " " +  workingPath + randomName + ".i.png" + " " +  "-compose" + " " +  "over" + " " +  workingPath + randomName + ".o.png" ); 
//						convert( "-bordercolor" + " " +  "none" + " " +  "-background" + " " +  "none" + " " +  workingPath + randomName + ".o.png" + " " +  "-implode" + " " +  "-1" + " " +  "-resize" + " " +  "105%" + " " +  "-rotate" + " " +  "2" + " " +  "-trim" + " " +  workingPath + randomName + ".o.png" ); 
//						break;
//					case 5:
//						composite( "-gravity" + " " +  "center" + " " +  workingPath + randomName + ".e.png" + " " +  workingPath + randomName + ".i.png" + " " +  "-compose" + " " +  "over" + " " +  workingPath + randomName + ".o.png" ); 
//						convert( "-bordercolor" + " " +  "none" + " " +  "-background" + " " +  "none" + " " +  workingPath + randomName + ".o.png" + " " +  "-implode" + " " +  "-1" + " " +  "-resize" + " " +  "105%" + " " +  "-rotate" + " " +  "-1" + " " +  "-trim" + " " +  workingPath + randomName + ".o.png" ); 
//						break;
//				}
//				Trace.Write("Converted: " + randomName + ".o.png" );
//
//				switch( frame ) 
//				{
//					case 1:
//					case 2:
//					case 4:
//					case 5:
//						composite( "-gravity" + " " +  "center" + " " +  workingPath + randomName + ".1.png" + " " +  workingPath + randomName + ".o.png" + " " +  "-compose" + " " +  "over" + " " +  workingPath + randomName + ".f.png" ); 
//						break;
//					case 3:
//						composite( "-gravity" + " " +  "center" + " " +  workingPath + randomName + ".1.png" + " " +  workingPath + randomName + ".i.png" + " " +  "-compose" + " " +  "over" + " " +  workingPath + randomName + ".f.png" ); 
//						break;
//				}
//				Trace.Write("Composite: " + randomName + ".f.png" );
//
//				composite( "-gravity" + " " +  "center" + " " +  workingPath + randomName + ".2.png" + " " +  workingPath + randomName + ".f.png" + " " +  "-compose" + " " +  "over" + " " +  workingPath + randomName + ".f.png" ); 
//				Trace.Write("Composite: " + randomName + ".f.png" );
//
//				convert( workingPath + randomName + ".f.png" + " " +  "-background" + " " +  "white" + " " +  "-rotate" + " " +  (rdm.Next(0 + " " + 10) < 4 ) ? (rdm.Next(1 + " " + 5).ToString()) : (rdm.Next(355 + " " + 359).ToString()) + " " +  "-trim" + " " +  "+repage" + " " +  "-quality" + " " +  "80" + " " +  thumb ); 
//				Trace.Write("Converted: " + thumb );
//			}
//
//			if( (sizes & frameit.Small) == frameit.Small ) 
//			{
//				Trace.Write( "Will be small.");
//
//				convert( source + " " +  "-trim" + " " +  "-resize" + " " +  "230x170" + " " +  "-bordercolor" + " " +  "none" + " " +  "-border" + " " +  "5" + " " +  workingPath + randomName + ".1.png" ); 
//				Trace.Write( "Converted: " + randomName + ".1.png" );
//
//				convert( "-bordercolor" + " " +  "none" + " " +  "-background", "none", "-compose", "Xor", "-gravity", "center", workingPath + randomName + ".1.png", workingPath + randomName + ".bg.png", "-composite", "-border", "5x5", "-blur", "1x1", "-trim", workingPath + randomName + ".2.png" ); 
//				Trace.Write("Converted: " + randomName + ".2.png" );
//
//				convert( workingPath + randomName + ".1.png", "-compose", "over", "-gravity", "center", workingPath + randomName + ".2.png", "-composite", "-shadow", "40x1", workingPath + randomName + ".s.png" ); 
//				Trace.Write("Converted: " +randomName + ".s.png" );
//
////				convert( "-background", "white", workingPath + randomName + ".1.png", "-compose", "over", "-gravity", "center", workingPath + randomName + ".s.png", "-composite", workingPath + randomName + ".f.png" ); 
////				Trace.Write("Composite: " + randomName + ".f.png" );
//
//				composite( "-gravity", "center", workingPath + randomName + ".2.png", workingPath + randomName + ".1.png", "-compose", "over", workingPath + randomName + ".f.png" ); 
//				Trace.Write("Composite: " + randomName + ".f.png" );
//
//				convert( workingPath + randomName + ".f.png", "-background", "white", "-trim", "+repage", "-quality", "80", small ); 
//				Trace.Write("Converted: " + small );
//			}
//
//			File.Delete( workingPath + randomName + ".1.png" );
//			File.Delete( workingPath + randomName + ".2.png" );
//			File.Delete( workingPath + randomName + ".bg.png" );
//			File.Delete( workingPath + randomName + ".s.png" );
//			File.Delete( workingPath + randomName + ".i.png" );
//			File.Delete( workingPath + randomName + ".e.png" );
//			File.Delete( workingPath + randomName + ".o.png" );
//			File.Delete( workingPath + randomName + ".f.png" );
//
//			Trace.Write("Deleted: pieces!");
//
//		}
//*/
//
///*
//		public void frame( string workingPath, string source, int sizes, string randomName, string thumb, string small, System.Web.TraceContext Trace )
//		{
//			Random rdm = new Random(unchecked((int)DateTime.Now.Ticks));
//			
//			int frame = rdm.Next(1,5);//frame = 2;
//			int bg = rdm.Next(1,14);//bg = 5;
//
//			Trace.Write( "Frame will be: " + frame.ToString() );
//			Trace.Write( "BG will be: " + bg.ToString() );
//
//			convert( workingPath + "pieces\\" + "bg0"+bg.ToString()+".png",	workingPath + randomName + ".bg.png" ); 
//			Trace.Write("Converted: " + randomName + ".bg.png");
//
//			if( (sizes & frameit.Thumb) == frameit.Thumb ) 
//			{
//				Trace.Write( "Will be thumb.");
//
//				convert( source, "-trim", "-resize", "90x90", "-bordercolor", "none", "-border", "5", workingPath + randomName + ".1.png" ); 
//				Trace.Write( "Converted: " + randomName + ".1.png" );
//
//				switch( frame ) 
//				{
//					case 1:
//						convert( "-bordercolor", "none", "-background", "none", "-compose", "Xor", "-gravity", "center", workingPath + randomName + ".1.png", workingPath + randomName + ".bg.png", "-composite", "-border", "5x5", "-blur", "1x1", "-trim", "-compose", "over", workingPath + "pieces\\" + "pin07.png", "-gravity", "NorthEast", "-composite", workingPath + "pieces\\" + "pin06.png", "-gravity", "SouthWest", "-composite", workingPath + randomName + ".2.png" ); 
//						break;
//					case 2:
//						convert( "-bordercolor", "none", "-background", "none", "-compose", "Xor", "-gravity", "NorthWest", workingPath + randomName + ".1.png", workingPath + randomName + ".bg.png", "-composite", "-border", "5x5", "-blur", "1x1", "-trim", "-compose", "over", workingPath + "pieces\\" + "pin01.png", "-gravity", "East", "-composite", workingPath + "pieces\\" + "pin02.png", "-gravity", "West", "-composite", workingPath + randomName + ".2.png" ); 
//						break;
//					case 3:
//						convert( "-bordercolor", "none", "-background", "none", "-compose", "Xor", "-gravity", "NorthWest", workingPath + randomName + ".1.png", workingPath + randomName + ".bg.png", "-composite", "-border", "5x5", "-blur", "1x1", "-trim", "-compose", "over", workingPath + "pieces\\" + "pin01.png", "-gravity", "NorthEast", "-composite", workingPath + "pieces\\" + "pin02.png", "-gravity", "SouthWest", "-composite", workingPath + "pieces\\" + "pin03.png", "-gravity", "SouthEast", "-composite", workingPath + "pieces\\" + "pin04.png", "-gravity", "NorthWest", "-composite", workingPath + randomName + ".2.png" ); 
//						break;
//					case 4:
//						convert( "-bordercolor", "none", "-background", "none", "-compose", "Xor", "-gravity", "NorthWest", workingPath + randomName + ".1.png", workingPath + randomName + ".bg.png", "-composite", "-border", "10x10", "-blur", "1x1", "-compose", "over", workingPath + "pieces\\" + "tape02.png", "-gravity", "East", "-composite", workingPath + "pieces\\" + "tape01.png", "-gravity", "West", "-composite", workingPath + randomName + ".2.png" ); 
//						break;
//					case 5:
//						convert( "-bordercolor", "none", "-background", "none", "-compose", "Xor", "-gravity", "NorthWest", workingPath + randomName + ".1.png", workingPath + randomName + ".bg.png", "-composite", "-border", "5x8", "-blur", "1x1", "-compose", "over", workingPath + "pieces\\" + "pin09.png", "-gravity", "north", "-composite", workingPath + randomName + ".2.png" ); 
//						break;
//				}
//				Trace.Write("Converted: " + randomName + ".2.png" );
//
//				switch( frame ) 
//				{
//					case 1:
//					case 2:
//					case 4:
//					case 5:
//						convert( workingPath + randomName + ".1.png", "-compose", "over", "-gravity", "center", workingPath + randomName + ".2.png", "-composite", "-shadow", "40x1", workingPath + randomName + ".s.png" ); 
//						break;
//					case 3:
//						break;
//				}
//				Trace.Write("Converted: " +randomName + ".s.png" );
//
//				switch( frame ) 
//				{
//					case 1:
//						convert( workingPath + randomName + ".s.png", "-bordercolor", "none", "-background", "none", "-border", "20x20", "-implode", ".4", "-chop", "6x6", workingPath + randomName + ".i.png" ); 
//						break;
//					case 2:
//					case 4:
//					case 5:
//						convert( workingPath + randomName + ".s.png", "-bordercolor", "none", "-background", "none", "-border", "20x20", "-implode", ".6", "-trim", "-splice", "5x5", workingPath + randomName + ".i.png" ); 
//						break;
//					case 3:
//						convert( "-bordercolor", "none", "-background", "none", workingPath + randomName + ".1.png", "-shadow", "40x1", "-shear", "5x0", "-border", "20x20", "-implode", "-1.3", "-trim", workingPath + randomName + ".i.png" ); 
//						break;
//				}
//				Trace.Write("Converted: " + randomName + ".i.png" );
//
//				switch( frame ) 
//				{
//					case 1:
//						convert( workingPath + randomName + ".s.png", "-bordercolor", "none", "-background", "none", "-border", "20x20", "-implode", "-1", "-chop", "6x6", "-trim", workingPath + randomName + ".e.png" ); 
//						break;
//					case 2:
//					case 4:
//						convert( workingPath + randomName + ".s.png", "-bordercolor", "none", "-background", "none", "-border", "20x20", "-implode", "-.5", "-splice", "5x5", workingPath + randomName + ".e.png" ); 
//						convert( workingPath + randomName + ".e.png", "-resize", "75%x95%", workingPath + randomName + ".e.png" ); 
//						break;
//					case 5:
//						convert( workingPath + randomName + ".s.png", "-bordercolor", "none", "-background", "none", "-border", "20x20", "-implode", "-.5", "-splice", "5x10", workingPath + randomName + ".e.png" ); 
//						convert( workingPath + randomName + ".e.png", "-resize", "75%x95%", workingPath + randomName + ".e.png" ); 
//						break;
//				}
//				Trace.Write("Converted: " + randomName + ".e.png" );
//
//				switch( frame ) 
//				{
//					case 1:
//						composite( "-gravity", "center", workingPath + randomName + ".e.png", workingPath + randomName + ".i.png", "-compose", "over", workingPath + randomName + ".o.png" ); 
//						convert( "-bordercolor", "none", "-background", "none", workingPath + randomName + ".o.png", "-shear", "0x1", "-shear", "-2x0", "-implode", ".6", "-splice", "4x4", "-shear", "-2x0", workingPath + randomName + ".o.png" ); 
//						break;
//					case 2:
//						composite( "-gravity", "center", workingPath + randomName + ".e.png", workingPath + randomName + ".i.png", "-compose", "over", workingPath + randomName + ".o.png" ); 
//						convert( "-bordercolor", "none", "-background", "none", workingPath + randomName + ".o.png", "-implode", "-1", "-resize", "105%", "-trim", "-rotate", "-1", workingPath + randomName + ".o.png" ); 
//						break;
//					case 4:
//						composite( "-gravity", "center", workingPath + randomName + ".e.png", workingPath + randomName + ".i.png", "-compose", "over", workingPath + randomName + ".o.png" ); 
//						convert( "-bordercolor", "none", "-background", "none", workingPath + randomName + ".o.png", "-implode", "-1", "-resize", "105%", "-rotate", "2", "-trim", workingPath + randomName + ".o.png" ); 
//						break;
//					case 5:
//						composite( "-gravity", "center", workingPath + randomName + ".e.png", workingPath + randomName + ".i.png", "-compose", "over", workingPath + randomName + ".o.png" ); 
//						convert( "-bordercolor", "none", "-background", "none", workingPath + randomName + ".o.png", "-implode", "-1", "-resize", "105%", "-rotate", "-1", "-trim", workingPath + randomName + ".o.png" ); 
//						break;
//				}
//				Trace.Write("Converted: " + randomName + ".o.png" );
//
//				switch( frame ) 
//				{
//					case 1:
//					case 2:
//					case 4:
//					case 5:
//						composite( "-gravity", "center", workingPath + randomName + ".1.png", workingPath + randomName + ".o.png", "-compose", "over", workingPath + randomName + ".f.png" ); 
//						break;
//					case 3:
//						composite( "-gravity", "center", workingPath + randomName + ".1.png", workingPath + randomName + ".i.png", "-compose", "over", workingPath + randomName + ".f.png" ); 
//						break;
//				}
//				Trace.Write("Composite: " + randomName + ".f.png" );
//
//				composite( "-gravity", "center", workingPath + randomName + ".2.png", workingPath + randomName + ".f.png", "-compose", "over", workingPath + randomName + ".f.png" ); 
//				Trace.Write("Composite: " + randomName + ".f.png" );
//
//				convert( workingPath + randomName + ".f.png", "-background", "white", "-rotate", (rdm.Next(0,10) < 4 ) ? (rdm.Next(1,5).ToString()) : (rdm.Next(355,359).ToString()), "-trim", "+repage", "-quality", "80", thumb ); 
//				Trace.Write("Converted: " + thumb );
//			}
//
//			if( (sizes & frameit.Small) == frameit.Small ) 
//			{
//				Trace.Write( "Will be small.");
//
//				convert( source, "-trim", "-resize", "230x170", "-bordercolor", "none", "-border", "5", workingPath + randomName + ".1.png" ); 
//				Trace.Write( "Converted: " + randomName + ".1.png" );
//
//				convert( "-bordercolor", "none", "-background", "none", "-compose", "Xor", "-gravity", "center", workingPath + randomName + ".1.png", workingPath + randomName + ".bg.png", "-composite", "-border", "5x5", "-blur", "1x1", "-trim", workingPath + randomName + ".2.png" ); 
//				Trace.Write("Converted: " + randomName + ".2.png" );
//
//				convert( workingPath + randomName + ".1.png", "-compose", "over", "-gravity", "center", workingPath + randomName + ".2.png", "-composite", "-shadow", "40x1", workingPath + randomName + ".s.png" ); 
//				Trace.Write("Converted: " +randomName + ".s.png" );
//
////				convert( "-background", "white", workingPath + randomName + ".1.png", "-compose", "over", "-gravity", "center", workingPath + randomName + ".s.png", "-composite", workingPath + randomName + ".f.png" ); 
////				Trace.Write("Composite: " + randomName + ".f.png" );
//
//				composite( "-gravity", "center", workingPath + randomName + ".2.png", workingPath + randomName + ".1.png", "-compose", "over", workingPath + randomName + ".f.png" ); 
//				Trace.Write("Composite: " + randomName + ".f.png" );
//
//				convert( workingPath + randomName + ".f.png", "-background", "white", "-trim", "+repage", "-quality", "80", small ); 
//				Trace.Write("Converted: " + small );
//			}
//
//			File.Delete( workingPath + randomName + ".1.png" );
//			File.Delete( workingPath + randomName + ".2.png" );
//			File.Delete( workingPath + randomName + ".bg.png" );
//			File.Delete( workingPath + randomName + ".s.png" );
//			File.Delete( workingPath + randomName + ".i.png" );
//			File.Delete( workingPath + randomName + ".e.png" );
//			File.Delete( workingPath + randomName + ".o.png" );
//			File.Delete( workingPath + randomName + ".f.png" );
//
//			Trace.Write("Deleted: pieces!");
//
//		}
//	}
//*/